/*
 * @Author: 梓岄 3049738225@qq.com
 * @Date: 2025-11-30 15:19:03
 * @LastEditors: 梓岄 3049738225@qq.com
 * @LastEditTime: 2025-11-30 15:45:53
 * @FilePath: /251130_signal/test3.cc
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */

#include<iostream>
#include<signal.h>

void Print(sigset_t& pending)
{
    for(int signo=64;signo>=34;signo--)
    {
        if(sigismember(&pending,signo))
        {
            std::cout<<"1";
        }
        else
        {
            std::cout<<"0";
        }
    }
    std::cout<<"  ";
    for(int signo=31;signo>0;signo--)
    {
        if(sigismember(&pending,signo))
        {
            std::cout<<"1";
        }
        else
        {
            std::cout<<"0";
        }
    }
    std::cout<<std::endl;
}

void sigcb(int signo)
{
    std::cout<<"接收到信号："<<signo<<std::endl;
    sigset_t pending;
    sigpending(&pending);
    std::cout<<"打印未决信号集："<<std::endl;
    Print(pending);
    std::cout<<"进程退出"<<std::endl;
    exit(0);
}

int main()
{

    signal(SIGQUIT,sigcb);

    sigset_t new_mask,old_mask;
    sigemptyset(&new_mask);
    sigaddset(&new_mask,2);
    sigaddset(&new_mask,40);

    sigprocmask(SIG_SETMASK,&new_mask,&old_mask);

    while(true)
    {
        std::cout<<"进程正在运行，pid: "<<getpid()<<std::endl;
        sleep(1);
    }

    return 0;
}